package com.colabo.j2ee.web.oaf.monitorperspective.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONArray;

import com.colabo.j2ee.web.core.context.ContextUtil;
import com.colabo.j2ee.web.core.exception.ServiceException;
import com.colabo.j2ee.web.oaf.monitorperspective.ILogDataService;

public class AccessMonitorViewAction {
	
	ILogDataService logDataService = (ILogDataService) ContextUtil.getBean(ILogDataService.BEAN_ID);
	
	public String loadLogData() throws Exception{
		String ret = "";
		HashMap map = new HashMap();
		
		List logDatas = logDataService.loadLogData(map, 0, 10);
		JSONArray json = JSONArray.fromObject(logDatas);
		ret = json.toString();
		return ret;
	}
	
	public String loadLogData(String page, String perPage) throws ServiceException, NumberFormatException {
		String ret = "";
		HashMap map = new HashMap();
		int _iPage = Integer.parseInt(page);
		int _iPerPage = Integer.parseInt(perPage);
		int offset = (_iPage-1) * _iPerPage;
		List logDatas = logDataService.loadLogData(map, offset, _iPerPage);
		int logDataCount = logDataService.getLogDataCount(map);
		
		Map resultMap = new HashMap();
		resultMap.put("page", page);
		resultMap.put("total", logDataCount);
		resultMap.put("data", logDatas);
		JSONArray json = JSONArray.fromObject(resultMap);
		ret = json.toString();
		return ret;
	}
}	
